using System.Collections.Generic;
using UnityEngine;

public static class FinderDeepChildren
{
	public static List<T> FindDeepChild<T>(Transform aParent, string tag = "Untagged")
	{
		List<T> list = new List<T>();
		Queue<Transform> queue = new Queue<Transform>();
		queue.Enqueue(aParent);
		while (queue.Count > 0)
		{
			Transform transform = queue.Dequeue();
			if (transform.GetComponent<T>() != null && transform.CompareTag(tag))
			{
				list.Add(transform.GetComponent<T>());
			}
			foreach (Transform item in transform)
			{
				queue.Enqueue(item);
			}
		}
		return list;
	}

	public static List<T> FindDeepChildNoTag<T>(Transform aParent)
	{
		List<T> list = new List<T>();
		Queue<Transform> queue = new Queue<Transform>();
		queue.Enqueue(aParent);
		while (queue.Count > 0)
		{
			Transform transform = queue.Dequeue();
			if (transform.GetComponent<T>() != null)
			{
				list.Add(transform.GetComponent<T>());
			}
			foreach (Transform item in transform)
			{
				queue.Enqueue(item);
			}
		}
		return list;
	}
}
